package com.oracle.oa.action;



import java.io.InputStream;
import java.util.Map;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.interceptor.SessionAware;

import com.opensymphony.xwork2.ActionSupport;
import com.oracle.oa.biz.BaseBiz;
import com.oracle.oa.biz.impl.OperatelogBizImpl;
import com.oracle.oa.entity.Accessoryfile;

public class AccessoryfileAction extends ActionSupport implements SessionAware{

	private static final long serialVersionUID = 1L;
	private Accessoryfile accessoryfile;
	

	private String downLoad; // 负责接收文件名
	private String inputPath; // 源文路径
    private long accessoryid;
    private String accessoryname;
    BaseBiz bBiz;
    private String url;
    private Map<String, Object> session=null;
    
    public String geturl(){
		if(session.get("url")!=null){
			url=session.get("url").toString();
		}else{
			url="";
		}
		return url;
	}
    /**
     * 下载文件
     * @return
     */
	public String downLoad() {
		Accessoryfile a=(Accessoryfile) bBiz.getById(Accessoryfile.class, accessoryid);
		accessoryname=a.getAccessoryname();
		OperatelogBizImpl.add("下载", "下载文件"+"\""+accessoryname+"\"");
		return "success";
	}

	

	/**
	 * 修改附件信息
	 * @return
	 */
	public String update() {
		bBiz.update(accessoryfile);
		return SUCCESS;
	}
    /**
     * 删除附件
     * @return
     */
	public String delete(){
		Accessoryfile a=(Accessoryfile) bBiz.getById(Accessoryfile.class, accessoryid);
		bBiz.delete(a);
		return SUCCESS;
	}
	
	

	/* 带有InputStream返回值的(get)方法 */
	public InputStream getTargetFile() {
		System.out.println(ServletActionContext.getServletContext().getResourceAsStream(
				inputPath + downLoad));
		return ServletActionContext.getServletContext().getResourceAsStream(
				inputPath + downLoad);
	}

	public Accessoryfile getAccessoryfile() {
		return accessoryfile;
	}

	public void setAccessoryfile(Accessoryfile accessoryfile) {
		this.accessoryfile = accessoryfile;
	}

	public static long getSerialversionuid() {
		return serialVersionUID;
	}

	public BaseBiz getbBiz() {
		return bBiz;
	}

	public void setbBiz(BaseBiz bBiz) {
		this.bBiz = bBiz;
	}

	

	public String getDownLoad() {
		return downLoad;
	}

	public void setDownLoad(String downLoad) {
		this.downLoad = downLoad;
	}

	public String getInputPath() {
		return inputPath;
	}

	public void setInputPath(String inputPath) {
		this.inputPath = inputPath;
	}

	public long getAccessoryid() {
		return accessoryid;
	}

	public void setAccessoryid(long accessoryid) {
		this.accessoryid = accessoryid;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public String getAccessoryname() {
		return accessoryname;
	}

	public void setAccessoryname(String accessoryname) {
		this.accessoryname = accessoryname;
	}
	public void setSession(Map<String, Object> arg0) {
		this.session=arg0;
		
	}
    
}
